package com.demo.dao;

import com.demo.entity.Account;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;

public class AccountDaoImpl implements AccountDao {
    
    private JdbcTemplate jdbcTemplate;
    
    public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
        this.jdbcTemplate = jdbcTemplate;
    }
    
    @Override
    public Account findAccountById(Integer id) {
        String sql = "select id, account_name as accountName, balance from account where id = ?";
        return jdbcTemplate.queryForObject(sql, new BeanPropertyRowMapper<>(Account.class), id);
    }
    
    @Override
    public Double queryBalance(Integer id) {
        String sql = "select balance from account where id = ?";
        return jdbcTemplate.queryForObject(sql, Double.class, id);
    }
    
    @Override
    public void updateBalance(Integer id, Double balance) {
        String sql = "update account set balance = ? where id = ?";
        jdbcTemplate.update(sql, balance, id);
    }
} 